import { CopyInfoPanelBase } from "../CopyInfoPanelBase";
import { Language } from "../../../../../extend/language/Language";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { ObjCreate } from "../../common/ObjCreate";
import { ResFileConst } from "../../../resource/ResFileConst";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { PageItemRenderer } from "../../common/renderers/PageItemRenderer";
import { CopyMaterialCanvas } from "./CopyMaterialCanvas";
import { SecTimerView } from "../../common/SecTimerView";
import { EventName } from "../../../mvc/EventName";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { CASCBossIntroView } from "./CASCBossIntroView";
import { DataEvent } from "../../../events/DataEvent";
import { FlyToNavbarTool } from "../../award/FlyToNavbarTool";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { CopyType } from "../CopyType";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
type int = number;
//class CrossAryadevaSecretCopyInfoView
    
    export  class CrossAryadevaSecretCopyInfoView extends CopyInfoPanelBase
    {
        constructor()
        {
            super();
            this._btnArr = [];
            this._btnLabelArr = [];
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc3=null;
            var loc4=null;
            super.createChildren();
            _bg.width = 260;
            _bg.height = 300;
            title = Language.getString(27606);
            this._textFormatTime1 = new GTextFormat(FontUtil.songtiName, 14, 65286);
            this._textFormatTime2 = new GTextFormat(FontUtil.songtiName, 14, 16580352);
            this._textFormatTime3 = new GTextFormat(FontUtil.songtiName, 14, 14884639);
            this._textFormatTime1.bold = true;
            this._textFormatTime2.bold = true;
            this._textFormatTime3.bold = true;
            var loc1=new GTextFormat(FontUtil.songtiName, 12, 16776960);
            loc1.leading = 14;
            this._killBossInfoText = ObjCreate.createTextField("", 12, 83, 210, 190, _bodySp, loc1);
            this._killBossInfoText.wordWrap = true;
            var loc2=0;
            while (loc2 < 5) 
            {
                loc3 = ObjCreate.createGLoadedButton(ResFileConst.CASCopyBossInfoBtn, 30, 106 + loc2 * 26, 24, 22, _bodySp);
                loc3.name = "boss_" + loc2;
                loc3.addEventListener(flash.events.MouseEvent.CLICK, this.showBossInfo);
                (loc4 = ObjCreate.createTextField(Language.getString(27611), 34, 110 + loc2 * 26, 20, 20, _bodySp)).filters = [FilterConst.textStrokeFilter()];
                loc4.mouseEnabled = false;
                loc4.selectable = false;
                this._btnArr.push(loc3);
                this._btnLabelArr.push(loc4);
                ++loc2;
            }
            this._rewards = ObjCreate.createTileList(30, 260, 230, 120, _bodySp);
            this._rewards.scrollPolicy = ScrollPolicy.OFF;
            this._rewards.columnWidth = 41;
            this._rewards.rowHeight = 41;
            this._rewards.setStyle("cellRenderer", PageItemRenderer);
            this._copyMaterial = new CopyMaterialCanvas();
            this._copyMaterial.x = 65;
            this._copyMaterial.y = -20;
            _bodySp.addChild(this._copyMaterial);
            this._tfLeftTime = new SecTimerView();
            this._tfLeftTime.setParse(Language.getString(42009));
            this._tfLeftTime.defaultTextFormat = this._textFormatTime1;
            this._tfLeftTime.filters = [FilterConst.glowFilter];
            ObjCreate.setObjAttri(this._tfLeftTime, 17, 60, 200, 20, _bodySp);
            this._tfLeftTime.addEventListener(EventName.SecViewTimeChange, this.onSecViewTimeChange);
            showPanel();
            this.addEventListeners();
            return;
        }

        /* internal  */addEventListeners(): void
        {
            Dispatcher.addEventListener(EventName.GetMultiplicityRewardSuccess, this.rewardFlutter);
            return;
        }

        /* internal  */showBossInfo(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc1=arg1.target as GLoadedButton;
            if (loc1) 
            {
                loc3 = (loc4 = loc1.name).split("_");
                loc2 = GameDefConfig.instance.getItem("CrossAryadevaSecretCopyBossIntro", int(loc3[1]));
                if (this._bossIntroView == null) 
                {
                    this._bossIntroView = new CASCBossIntroView();
                    this._bossIntroView.x = -300;
                    this._bossIntroView.y = 55;
                }
                if (!this.contains(this._bossIntroView)) 
                {
                    this.addChild(this._bossIntroView);
                }
                this._bossIntroView.updateBossInfo(loc2);
            }
            return;
        }

        /* internal  */rewardFlutter(arg1: DataEvent): void
        {
            var loc2=null;
            var loc3=null;
            if (this._rewards == null) 
            {
                return;
            }
            var loc1=this._rewards.dataProvider;
            var loc4=0;
            if (loc1) 
            {
                while (loc4 < loc1.length) 
                {
                    loc2 = this._rewards.itemToCellRenderer(loc1.getItemAt(loc4)) as PageItemRenderer;
                    if (loc2 && loc2.item) 
                    {
                        if (_zoomBtn.show) 
                        {
                            loc3 = this._rewards.localToGlobal(new Object /* flash.geom.Point */(loc2.x, loc2.y));
                        }
                        else 
                        {
                            loc3 = _zoomBtn.parent.localToGlobal(new Object /* flash.geom.Point */(_zoomBtn.x + loc2.width * loc4 + 10, _zoomBtn.y));
                        }
                        FlyToNavbarTool.flyToBackPack(loc2.item.bitmapdata, loc3);
                    }
                    ++loc4;
                }
            }
            Dispatcher.removeEventListener(EventName.GetMultiplicityRewardSuccess, this.rewardFlutter);
            return;
        }

        /* internal  */onSecViewTimeChange(arg1: DataEvent): void
        {
            var loc2=null;
            var loc1=int(arg1.data);
            if (loc1 == 15 && this._rewards && this._rewards.dataProvider.length > 0) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.LeaveCrossAryadevaSecretCopyAndShowRewardView, {"showReturnBtn": true}));
            }
            if (loc1 >= 10 * 60) 
            {
                this._tfLeftTime.setTextFormat(this._textFormatTime1);
            }
            else if (loc1 >= 5 * 60) 
            {
                this._tfLeftTime.setTextFormat(this._textFormatTime2);
            }
            else 
            {
                this._tfLeftTime.setTextFormat(this._textFormatTime3);
            }
            return;
        }

        /* internal  */updateBgHeight(arg1: int): void
        {
            if (arg1 <= 5) 
            {
                _bg.height = 300;
            }
            else if (arg1 > 5 && arg1 <= 10) 
            {
                _bg.height = 345;
            }
            else if (arg1 > 10) 
            {
                _bg.height = 390;
            }
            return;
        }

        protected /* override */ onZoomBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (_zoomBtn.show) 
            {
                hidePanel();
                if (this._copyMaterial) 
                {
                    this._copyMaterial.stretchView(_zoomBtn);
                }
            }
            else 
            {
                showPanel();
                if (this._copyMaterial) 
                {
                    this._copyMaterial.stretchView(null);
                }
            }
            return;
        }

        public get bodySp(): Object /* flash.display.Sprite */
        {
            return _bodySp;
        }

        public updateLeftTime(arg1: int): void
        {
            this._tfLeftTime.setLeftTime(arg1);
            return;
        }

        public stopLeftTime(): void
        {
            this._tfLeftTime.stop();
            return;
        }

        public updataKillBossInfo(arg1: string): void
        {
            if (this._killBossInfoText && arg1) 
            {
                this._killBossInfoText.htmlText = arg1;
            }
            return;
        }

        public updataAwardInfo(arg1: Array<any>): void
        {
            if (this._rewards) 
            {
                this.updateBgHeight(arg1.length);
                this._rewards.dataProvider = new DataProvider(arg1);
                this._rewards.drawNow();
            }
            return;
        }

        public updatacopyMaterial(arg1: Array<any>): void
        {
            if (this._copyMaterial) 
            {
                this._copyMaterial.setMaterials(arg1);
            }
            return;
        }

        public clean(): void
        {
            if (this._tfLeftTime) 
            {
                this._tfLeftTime.dispose();
            }
            if (this._rewards && this._rewards.parent) 
            {
                this._rewards.parent.removeChild(this._rewards);
                this._rewards = null;
            }
            if (this._copyMaterial && this._copyMaterial.parent) 
            {
                this._copyMaterial.stretchView(null);
                this._copyMaterial.parent.removeChild(this._copyMaterial);
                this._copyMaterial = null;
            }
            return;
        }

        public set copyType(arg1: int)
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            this._copyType = arg1;
            if (this._copyType != CopyType.CROSS_ARYADEVA_SECRET_COPY) 
            {
                if (this._copyType == CopyType.UPGRARE_CROSS_SECRET_COPY) 
                {
                    if (this._copyMaterial && this._copyMaterial.parent) 
                    {
                        this._copyMaterial.parent.removeChild(this._copyMaterial);
                    }
                    loc3 = 0;
                    loc3 = 0;
                    while (loc3 < this._btnArr.length) 
                    {
                        loc1 = this._btnArr[loc3];
                        loc2 = this._btnLabelArr[loc3];
                        if (loc1 && loc1.parent) 
                        {
                            loc1.parent.removeChild(loc1);
                        }
                        if (loc2 && loc2.parent) 
                        {
                            loc2.parent.removeChild(loc2);
                        }
                        ++loc3;
                    }
                    this._killBossInfoText.y = 43;
                    this._rewards.y = 220;
                    this._tfLeftTime.y = 15;
                    title = Language.getString(27614);
                }
            }
            else 
            {
                title = Language.getString(27606);
            }
            return;
        }

        /* internal */ /* var */_copyType: int=163;

        /* internal */ /* var */_tfLeftTime: SecTimerView;

        /* internal */ /* var */_killBossInfoText: Object /* flash.text.TextField */;

        /* internal */ /* var */_rewards: GTileList;

        /* internal */ /* var */_copyMaterial: CopyMaterialCanvas;

        /* internal */ /* var */_bossIntroView: CASCBossIntroView;

        /* internal */ /* var */_textFormatTime1: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_textFormatTime2: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_textFormatTime3: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_btnArr: Array<any>;

        /* internal */ /* var */_btnLabelArr: Array<any>;
    }
